<?php
/**
 * 系统设置
 * @author Administrator
 *
 */
namespace app\admin\controller;
use app\common\model\HuiYuanSupervise;
use app\admin\controller\Base;
use think\Db;
use app\common\model\SystemSet;

class Systemsettings extends Base
{
	protected $system;
	public function _initialize(){
		parent::_initialize();
		$category = Db::name('menu')->where('parent_id',15)->select();
		$this->assign('category',$category);
		$this->member_model= new HuiYuanSupervise();
		return $this->system = new SystemSet();
	}
	/**
	 * 系统相关设置
	 * @param string $title
	 * @param string $keyword
	 * @param string $miaoshi
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_xtsz(){
		
		
			$xt_jichu = Db::name('xt_jichu')->find();
			$this->assign('jichu',$xt_jichu);
			
		
		if(input('post.')){	
			Db::startTrans();	
			try {
				$data=array(
					'open'=>input('post.WZKG'),
					'test'=>input('post.TEST')
				);
				$where=array('id'=>1);
				
				$this->system->dUpdate('xt_off_or_no',$where, $data);
				$xt_jichu2 = Db::name('xt_jichu')->find();
				$data2 = array(
						'title'=>input('title'),
						'keyword'=>input('keyword'),
						'miaoshi'=>input('miaoshi'),
						'logoimg'=>input('logoimg'),
						'id'=>1
				);
				
				Db::name('xt_jichu')->where('id',$xt_jichu2['id'])->delete();
				$addjichu2=Db::name('xt_jichu')->insert($data2);
				$this->system->CaoZuoJl(1, '修改了网站信息设置', time(), $this->system->GetIP(), $_COOKIE['user']);					
				
				Db::commit();
			}catch (\Exception $e){
				Db::rollback();
				$this->system->alertWin('设置失败', url('Systemsettings/ht_xtsz'));
			}
			$this->system->alertWin('设置成功', url('Systemsettings/ht_xtsz'));
		}else{
			Db::startTrans();
			try {
				$list = $this->system->dList('xt_off_or_no');
				
				$this->assign('list',$list);
				
				if($list['open']==1){
					
					$wzkg="checked";
					
					$wzkg_0='';
					
				}elseif($list['open']==0){
					
					$wzkg_0="checked";
						
					$wzkg='';
				}
				
				$this->assign('wzkg',$wzkg);
				
				$this->assign('wzkg_0',$wzkg_0);
				
				Db::commit();
			}catch (\Exception $e){
				Db::rollback();
			}
			
		}
			return $this->fetch();
		
	}
	public function xtsz_ht(){
		
		$xt_jichu = Db::name('xt_jichu')->find();
		$data = array(
				'title'=>input('title'),
				'keyword'=>input('keyword'),
				'miaoshi'=>input('miaoshi'),
				'logoimg'=>input('logoimg'),
				'id'=>1
		);
		if($xt_jichu){
			Db::name('xt_jichu')->where('id',$xt_jichu['id'])->delete();
			$addjichu=Db::name('xt_jichu')->insert($data);
		}

		if($addjichu){
			$this->system->CaoZuoJl(1, '修改了平台版权与LOGO信息', time(), $this->system->GetIP(), $_COOKIE['user']);

			return '1';	
		}else{
			return '2';
		}
	}
	/**
	 * 网站开关
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_wzkg(){
		
		Db::startTrans();
		
		if(input('post.')){		
			try {
				$data=array(
					'open'=>input('post.WZKG'),
					'test'=>input('post.TEST')
				);
				$where=array('id'=>1);
				$this->system->CaoZuoJl(1, '开启了网站并修改关闭说明', time(), $this->system->GetIP(), $_COOKIE['user']);
				$this->system->dUpdate('xt_off_or_no',$where, $data);
				Db::commit();
			}catch (\Exception $e){
				Db::rollback();
				$this->system->alertWin('设置失败', url('Systemsettings/ht_wzkg?id='.input('param.id').'&cid='.input('param.cid')));
			}
			$this->system->alertWin('设置成功', url('Systemsettings/ht_wzkg?id='.input('param.id').'&cid='.input('param.cid')));
		}else{
			Db::startTrans();
			try {
				$list = $this->system->dList('xt_off_or_no');
				
				$this->assign('list',$list);
				
				if($list['open']==1){
					
					$wzkg="checked";
					
					$wzkg_0='';
					
				}elseif($list['open']==0){
					
					$wzkg_0="checked";
						
					$wzkg='';
				}
				
				$this->assign('wzkg',$wzkg);
				
				$this->assign('wzkg_0',$wzkg_0);
				
				Db::commit();
			}catch (\Exception $e){
				Db::rollback();
			}
			return $this->fetch();
		}
	}
	/**
	 * 外部客服
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_wbkf(){
	    $type = input('get.kftype') ? input('get.kftype') : 1;
	    if($type != 4){
	    	if($type==1){
	       		$list = Db::name('xt_kflink')->where('type','IN','0,1')->select();
	    	}elseif($type==2){
	    		$list = Db::name('xt_kflink')->where('type','IN','2,3')->select();
	    	}else{
	    		$list = Db::name('xt_kflink')->where('type',$type)->select();
	    	}
	       		
	    }else{
	        $list = Db::name('xt_kflink')->where('type',4)->find();
	    }
	    $this->assign('type',$type);
		
		$this->assign('list',$list);
		return $this->fetch();
	}
	public function emailTixing(){
		$list = Db::name('xt_kflink')->where('type',5)->select();
		$this->assign('list',$list);
		
		return $this->fetch('email_tixing');
	}
	public function email_add(){
		return $this->fetch();
	}
	public function kf_open(){
		$type = input('type');
		$status = input('status');
		if($type==1){
			Db::name('xt_kflink')->where('type','IN','0,1')->update(array('status'=>$status));
		}elseif($type==2){
			Db::name('xt_kflink')->where('type','IN','2,3')->update(array('status'=>$status));
		}else{
			Db::name('xt_kflink')->where('type',$type)->update(array('status'=>$status));
		}
		return 1;
	}
	
	/**
	 * 客服是否可用
	 */
	public function serviceStatus(){
	    $id = input('get.id');
		$kftype = input('get.kftype','');
		if($kftype==5){
			$type="邮件提醒客服";
		}
		if($kftype==2){
			$type="微信客服";
		}
		if($kftype==1 || $kftype ==''){
			$type="QQ客服";
		}

	    $status = input('get.status');
	    $kefu=Db::name('xt_kflink')->where(['id'=>$id])->find();
	    if($status==0){
	    	$zhuangtai="禁用";
	    }
	    if($status==1){
	    	$zhuangtai="正常";
	    }
	    Db::name('xt_kflink')->where(['id'=>$id])->update(['status'=>$status]);
	    $this->member_model->caozuorizhi_xieru('设置'.$type.':“'.$kefu['name'].'”为:'.$zhuangtai);
	    $this->redirect('/admin/Systemsettings/ht_wbkf?kftype='.$kftype);
	}
	
	/**
	 * 新增客服
	 * @return \think\mixed
	 */
	public function ht_servicenew(){
	
	  return $this->fetch();
	    
	}
	public function add_kefu(){
		$name = input('name');
		$qq = input('qq');
		$type = input('type');
		if($type==5){
			$typename="邮件提醒客服";
		}
		if($type==3){
			$typename="会员微信客服";
		}
		if($type==2){
			$typename="游客微信客服";
		}
		if($type==1){
			$typename="会员QQ客服";
		}
		if($type==''){
			$typename="游客QQ客服";
		}
		$data = array('name'=>$name,'qq'=>$qq,'type'=>$type,'status'=>1);
		if($type == 4){
		    $searchfind = Db::name('xt_kflink')->where('type',4)->find();
		    if($searchfind){
		        $update = Db::name('xt_kflink')->where('type',4)->update($data);
		        if($update){
		        	$this->member_model->caozuorizhi_xieru('修改在线客服信息');
		            return 1;
		        }else{
		            return 0;
		        }
		    }
		}
		$add_kf = Db::name('xt_kflink')->insert($data);
		if($name==''){
			echo 2;
		}
		if($qq==''){
			echo 3;
		}
		if($add_kf){
			$this->member_model->caozuorizhi_xieru('添加客服:“'.$name.'”类型是:'.$typename);
			echo 1;
		}else{
			echo 0;
		}
	}
	
	/**
	 * 删除客服
	 */
	public function serviceDel(){
	    $id = input('get.id');
		$kftype = input('get.kftype','');
		if($kftype==5){
			$type="邮件提醒客服";
		}
		if($kftype==3){
			$type="会员微信客服";
		}
		if($kftype==2){
			$type="游客微信客服";
		}
		if($kftype==1){
			$type="会员QQ客服";
		}
		if($kftype==''){
			$type="游客QQ客服";
		}

		$kefu=Db::name('xt_kflink')->where(['id'=>$id])->find();
	    Db::name('xt_kflink')->where(['id'=>$id])->delete();
	    $this->member_model->caozuorizhi_xieru('删除客服:“'.$kefu['name'].'”，类型是:'.$type);
	    $this->redirect('/admin/Systemsettings/ht_wbkf?id=19&cid=15&kftype='.$kftype);
	}
	public function emailserviceDel(){
		$id = input('get.id');
		$kefu=Db::name('xt_kflink')->where(['id'=>$id])->find();
		Db::name('xt_kflink')->where(['id'=>$id])->delete();
		$this->member_model->caozuorizhi_xieru('删除客服:“'.$kefu['name'].'”，类型是:邮箱提醒客服');
		$this->redirect('/admin/Systemsettings/emailTixing');
	}
	
	/**
	 * 统计代码
	 * @param  $tjdm
	 * @return Ambigous <\think\mixed, string>
	 */
// 	public function ht_tjdm($tjdm=''){
// 		if(input('post.')){
			
// 			if($tjdm != ''){
// 				$where=array('id'=>1);
				
// 				$data=array('count_dm'=>$tjdm);
// 				$this->system->CaoZuoJl(1, '更改了代码统计', time(), $this->system->GetIP(), $_COOKIE['user']);
// 				return $this->system->dUpdate('xt_tjdm', $where,$data, '更新成功', url('Systemsettings/ht_tjdm?id='.input('param.id').'&cid='.input('param.cid')));
// 			}else{
// 				$data=array('count_dm'=>$tjdm);
				
// 				return $this->system->dInsert('xt_tjdm', $data, '添加成功', url('Systemsettings/ht_tjdm?id='.input('param.id').'&cid='.input('param.cid')));
// 			}
// 		}else
		
// 			$list = $this->system->dList('xt_tjdm');
			
// 			$this->assign('list',$list);
			
// 			return $this->fetch();
// 	}
	/**
	 * 	充值金额设置
	 * @param string $xscz_je
	 * @param string $xscz_zs
	 * @param string $xxcz_je
	 * @param string $xxcz_zs
	 * @param string $dmopen
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_czsz($xscz_je='',$xscz_zs='',$xxcz_je='',$xxcz_zs='',$dmopen='')
	{
		
		Db::startTrans();
		if(input('post.')){
			
			if($xscz_je != '' && $xscz_zs != '' && $xxcz_je != '' && $xxcz_zs != '' && $dmopen != '')
			{
				$data=array('xscz_je'=>$xscz_je,'xscz_zs'=>$xscz_zs,'xxcz_je'=>$xxcz_je,'xxcz_zs'=>$xxcz_zs,'dmopen'=>$dmopen);
				
				$where = array('id'=>1);
				
				try {
					$this->system->CaoZuoJl(1, '修改了充值赠送金额设置', time(), $this->system->GetIP(), $_COOKIE['user']);
					$this->system->dUpdate('xt_chongzhi', $where,$data);
					
					Db::commit();
				}catch (\Exception $e){
					Db::rollback();
					$this->system->alertWin('设置失败', url('Systemsettings/ht_czsz').'?id='.input('param.id').'&cid='.input('param.cid'));
				}
				$this->system->alertWin('设置成功', url('Systemsettings/ht_czsz').'?id='.input('param.id').'&cid='.input('param.cid'));
			}
			
		}else{
		
			$list = $this->system->dList('xt_chongzhi');
			
			$this->assign('list',$list);
			//2
			$query = $this->system->dList('xt_tixian');
			
			$this->assign('query',$query);
			//3
			$query3 = $this->system->dList('xt_dmsz');
			
			$this->assign('query3',$query3);
			//4
			$query4 = $this->system->dList('xt_czfsr');
			$this->assign('query4',$query4);
			return $this->fetch();
		}
	}
	/**
	 * 提取现金设置
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_txsz()
	{
		Db::startTrans();
		if(input('post.')){
			
			$data = array('test'=>input('post.test'),'zxje'=>input('post.zxje'),'zdje'=>input('post.zdje'),'txcount'=>input('post.txcount'),'open'=>input('post.open'));
			
			$where=array('id'=>1);
			try{
				$this->system->CaoZuoJl(1, '修改了提现金额设置', time(), $this->system->GetIP(), $_COOKIE['user']);
				$this->system->dUpdate('xt_tixian',$where, $data);
				Db::commit();
			}catch (\Exception $e){
				Db::rollback();
				$this->system->alertWin('更新失败', url('Systemsettings/ht_txsz?id='.input('param.id').'&cid='.input('param.cid')));
			}
			$this->system->alertWin('更新成功', url('Systemsettings/ht_txsz?id='.input('param.id').'&cid='.input('param.cid')));
			
		}else{
			$query = $this->system->dList('xt_tixian');
			
			$this->assign('query',$query);
			
			return $this->fetch();
		}
	}
	/**
	 * 打码设置
	 * @param string $xscz_dmbs
	 * @param string $xxcz_dmbs
	 * @param string $tx_yzdml
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_dmsz($xscz_dmbs='',$xxcz_dmbs='',$tx_yzdml='')
	{
		Db::startTrans();
		if(input('post.')){
			
			if($xscz_dmbs != '' && $xxcz_dmbs != '' && $tx_yzdml != '')
			{
			
				$data = array('xscz_dmbs'=>$xscz_dmbs,'xxcz_dmbs'=>$xxcz_dmbs,'tx_yzdml'=>$tx_yzdml);
				
				$where = array('id'=>1);
				try{
					$this->system->CaoZuoJl(1, '修改了打码设置', time(), $this->system->GetIP(), $_COOKIE['user']);
					$this->system->dUpdate('xt_dmsz',$where, $data);
					Db::commit();
				}catch (\Exception $e){
					Db::rollback();
					$this->system->alertWin('更新失败', url('Systemsettings/ht_dmsz?id='.input('param.id').'&cid='.input('param.cid')));
				}
				$this->system->alertWin('更新成功', url('Systemsettings/ht_dmsz?id='.input('param.id').'&cid='.input('param.cid')));
			
			}
				
		}else{
			$query = $this->system->dList('xt_dmsz');
			
			$this->assign('query',$query);
			
			return $this->fetch();
		}
	}
	/**
	 * 注册防骚扰
	 * @param string $one_day_count
	 * @param string $one_pc_count
	 * @param string $open
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_zcfy($one_day_count='',$one_pc_count='',$open='')
	{
		$cj = Db::name('xt_caijin')->where('id',1)->find();
		$ids=array();
		$ids['id']=input('id');
		$ids['cid']=input('cid');
		$this->assign('cj',$cj);
		$this->assign('ids',$ids);
		Db::startTrans();
		if(input('post.')){
			if($one_day_count != '' && $one_pc_count != '' && $open != ''){
				$data = array('one_day_count'=>$one_day_count,'one_pc_count'=>$one_pc_count,'open'=>$open);			
				$where = array('id'=>1);
				try{	
					$this->system->CaoZuoJl(1, '更新了注册防骚扰', time(), $this->system->GetIP(), $_COOKIE['user']);
					$this->system->dUpdate('xt_zcfsr',$where, $data);

					
					Db::commit();
				}catch (\Exception $e){
					Db::rollback();
					$this->system->alertWin('更新失败', url('Systemsettings/ht_zcfy?id='.input('param.id').'&cid='.input('param.cid')));
				}
				$this->system->alertWin('更新成功', url('Systemsettings/ht_zcfy?id='.input('param.id').'&cid='.input('param.cid')));
			}
		}else{
			$query = $this->system->dList('xt_zcfsr');
			$this->assign('query',$query);
			
			return $this->fetch();
		}
	}
	/**
	 * 充值防骚扰
	 * @param string $time_xs
	 * @param string $time_xx
	 * @param string $open
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_czfy()
	{
		if(input('post.')){
			$data = array('time_xs'=>input('post.time_xs'),'time_xx'=>input('post.time_xx'),'open'=>input('post.open'));
			$where = array('id'=>1);
			
			$this->system->CaoZuoJl(1, '修改了充值防骚扰', time(), $this->system->GetIP(), $_COOKIE['user']);
			if(Db::name('xt_czfsr')->where($where)->update($data)){
					js_tishi('更新成功', url('Systemsettings/ht_czfy'));
				}else{
					alert_back('更新失败');
				}
		}else{
			$query = $this->system->dList('xt_czfsr');
			$this->assign('query',$query);
			
			return $this->fetch();
		}
	}
	/**
	 * 账号注册设置
	 * @param string $codo_open
	 * @param string $tjr_open
	 * @param string $fandian
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_zcsz($codo_open='',$tjr_open='',$fandian='')
	{
		if(input('post.')){
			if($codo_open != '' && $tjr_open != '' ){
				$data = array('codo_open'=>$codo_open,'tjr_open'=>$tjr_open,'fandian'=>$fandian);
				$where = array('id'=>1);
				$this->system->CaoZuoJl(1, '修改了账号注册设置', time(), $this->system->GetIP(), $_COOKIE['user']);
				$this->system->dUpdate('xt_reg',$where, $data);
				return $this->system->alertWin('更新成功', url('Systemsettings/ht_zcsz?id='.input('param.id').'&cid='.input('param.cid')));
			}
		}else {
			$query = $this->system->dList('xt_reg');
			$this->assign('query',$query);
			return $this->fetch();
		}
	}
	/**
	 * 投注模式设置
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_tzsz()
	{	
		if(input('post.')){
			$data = array('yuan'=>input('post.yuan'),'jiao'=>input('post.jiao'),'zhuihao'=>input('post.zhuihao'));
			$where = array('id'=>1);
			$this->system->CaoZuoJl(1, '修改了投注模式设置', time(), $this->system->GetIP(), $_COOKIE['user']);
			$this->system->dUpdate('xt_tzms',$where, $data);
			return $this->system->alertWin('设置成功', url('Systemsettings/ht_tzsz'));
		}else{
			$query = $this->system->dList('xt_tzms');
			$this->assign('query',$query);
			return $this->fetch();
		}
	}
	/**
	 * 试玩账号设置
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_swsz()
	{
		if(input('post.')){
			$data = array('qianzhui'=>input('post.qianzhui'),'swcd'=>input('post.swcd'),'je'=>input('post.je'),'open'=>input('post.open'));
			
			$where = array('id'=>1);
			$this->system->CaoZuoJl(1, '修改了试玩账号设置', time(), $this->system->GetIP(), $_COOKIE['user']);
			$this->system->dUpdate('xt_shiwan',$where, $data);
			return $this->system->alertWin('设置成功', url('Systemsettings/ht_swsz?id='.input('param.id').'&cid='.input('param.cid')));
		}else{
			$query = $this->system->dList('xt_shiwan');
			$this->assign('query',$query);
			return $this->fetch();
		}
	}
	/**
	 * 充值提现提醒设置
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_cttxsz()
	{	
		$where=array('xxcz'=>1);
		$xxmic=$this->system->dFind('xt_tishi_msic',$where);
		$this->assign('xxmic',$xxmic);
			
		$where=array('xscz'=>1);
		$xsmic=$this->system->dFind('xt_tishi_msic',$where);
		$this->assign('xsmic',$xsmic);
			
		$where=array('tx'=>1);
		$txmic=$this->system->dFind('xt_tishi_msic',$where);
		$this->assign('tx',$txmic);
			
		$list = $this->system->dLists('xt_tishi_msic');
		$this->assign('list',$list);
		if(input('post.')){
			foreach ($list as $v){
				$data_a=array('xxcz_class'=>0,'xxcz'=>0,'xxcz_open'=>0,'xscz_class'=>0,'xscz'=>0,'xscz_open'=>0,'tx'=>0,'tx_open'=>0,'tx_class'=>0);
				$where_a=array('id'=>$v['id']);
				Db::name('xt_tishi_msic')->where($where_a)->update($data_a);
			}
			$where_1 = array('id'=>input('post.mp3_lj'));
			$data_1 = array('xxcz_class'=>input('post.xxcz_class'),'xxcz_open'=>input('post.xxcz_open'),'xxcz'=>1);
			$mic=Db::name('xt_tishi_msic')->where($where_1)->update($data_1);
			
			$where_2 = array('id'=>input('post.mp3_lj_xs'));
			$data_2 = array('xscz_class'=>input('post.xscz_class'),'xscz_open'=>input('post.xscz_open'),'xscz'=>1);
			$mic=Db::name('xt_tishi_msic')->where($where_2)->update($data_2);
			
			$where_3 = array('id'=>input('post.mp3_lj_tx'));
			$data_3 = array('tx_class'=>input('post.tx_class'),'tx_open'=>input('post.tx_open'),'tx'=>1);
			$mic=Db::name('xt_tishi_msic')->where($where_3)->update($data_3);
			$this->system->CaoZuoJl(1, '修改了充值提现提醒设置', time(), $this->system->GetIP(), $_COOKIE['user']);
			return $this->system->alertWin('设置成功', url('Systemsettings/ht_cttxsz?id='.input('param.id').'&cid='.input('param.cid')));
		}
			return $this->fetch();
	}
	public function postMicList(){
		return $this->system->postMicList();
	}
	/**
	 * 注册赠送彩金
	 * @return Ambigous <\think\mixed, string>
	 */
	public function ht_zczscj(){
		$cj = Db::name('xt_caijin')->where('id',1)->find();
		$ids=array();
		$ids['id']=input('id');
		$ids['cid']=input('cid');
		$this->assign('cj',$cj);
		$this->assign('ids',$ids);
		return $this->fetch();
	}
	public function cjtj(){
		$je = input('je')?input('je'):0;
		$dml = input('dml')?input('dml'):0;
		$open = input('open')?input('open'):0;
		$this->system->CaoZuoJl(1, '修改了注册送彩金', time(), $this->system->GetIP(), $_COOKIE['user']);
		return $this->system->zczscj($je, $dml, $open);
	}
	/**
	 * 下级代理设置
	 */
	public function ht_dailisz(){
		$dl = Db::name('xt_dl')->where('id',1)->find();
		$this->assign('dl',$dl);
		return $this->fetch();	
	}
	public function dltj(){
		$max = input('max') ? input('max') : 0;
		return $this->system->dltj($max);
	}
}